//
//  StatusCell.swift
//  ShangHaiWeiBo
//
//  Created by 蔡杰 on 16/3/1.
//  Copyright © 2016年 蔡杰. All rights reserved.
//

import UIKit
import SnapKit
class StatusCell: UITableViewCell {

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    var viewModel:StatusViewModel?{
    
        didSet{
        
            originalView.viewModel = viewModel
            retwteedView.viewModel = viewModel
        }
    }
    //私有控件属性
    private let originalView:StatusOriginalView = StatusOriginalView()
    private let retwteedView:StatusRetweetedView = StatusRetweetedView()
    private let toolbar: StatusToolbar = StatusToolbar()
    
}

extension StatusCell {

    private func setupUI(){
    
//        backgroundColor = UIColor.redColor()
        backgroundColor = UIColor.cz_colorWithHex(0xF2F2F2)
        contentView.addSubview(originalView)
        contentView.addSubview(retwteedView)
        contentView.addSubview(toolbar)
        //自动布局
//        let margin = CZStatusCellLayout.margin
       originalView.snp_makeConstraints { (make) -> Void in
        
        make.top.equalTo(contentView)
        make.left.equalTo(contentView)
        make.right.equalTo(contentView)
        
        }
        retwteedView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(originalView.snp_bottom)
            make.left.equalTo(contentView)
            make.right.equalTo(contentView)
            
        }
        toolbar.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retwteedView.snp_bottom)
            make.right.equalTo(contentView)
            make.left.equalTo(contentView)
            make.height.equalTo(36)
        }
        contentView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.left.equalTo(self)
            make.right.equalTo(self)
            make.bottom.equalTo(toolbar)
        }
        self.layer.drawsAsynchronously = true
        
        self.layer.shouldRasterize = true
        
        self.layer.rasterizationScale = UIScreen.mainScreen().scale
        
    }
    
}